package org.dzms.dao;


import java.util.List;

import org.dzms.commons.DataHandler;
import org.dzms.commons.IPage;
import org.dzms.commons.PageHandler;
import org.dzms.commons.sqlHandler;
import org.dzms.entity.FoodDetails;
import org.dzms.entity.FoodRevDeta;
import org.dzms.entity.UserReview;



public class FoodDetailsDAO implements IPage {
	/**
	 * 商户详细信息
	 */
	
	
	//查询所有用户输入点评
		public List<FoodRevDeta> findAllFes(){
			String sql = "select * from foodrevdeta order by feid desc";
			return DataHandler.query(sql, null, FoodRevDeta.class);
		}
//	private List<FoodDetails> change(String sql,Object [] params){
//		ResultSet rs = DbManager.query(sql,params);
//		List<FoodDetails> fds = new ArrayList<FoodDetails>();
//		try {
//			while(rs.next()){
//				FoodDetails fd = new FoodDetails();
//				fd.setFdid(rs.getInt("fdid"));
//				fd.setFdname(rs.getString("fdname"));
//				fd.setFdcomment(rs.getString("fdcomment"));
//				fd.setFdperpay(rs.getString("fdperpay"));
//				fd.setFdtaste(rs.getFloat("fdtaste"));
//				fd.setFdenvironment(rs.getFloat("fdenvironment"));
//				fd.setFdservice(rs.getFloat("fdservice"));
//				fd.setFdaddress(rs.getString("fdaddress"));
//				fd.setFddetaddress(rs.getString("fddetaddress"));
//				fd.setFdtel(rs.getString("fdtel"));
//				fd.setFdbushours(rs.getString("fdbushours"));
//				fd.setFdprice(rs.getString("fdprice"));
//				fd.setFdpricepic(rs.getString("fdpricepic"));
//				fd.setFdpricename(rs.getString("fdpricename"));
//				fd.setFdrecdis(rs.getString("fdrecdis"));
//				fd.setFdrecdispic(rs.getString("fdrecdispic"));
//				fd.setFdenvironmentpic(rs.getString("fdenvironmentpic"));
//				fd.setFdpricelistpic(rs.getString("fdpricelistpic"));
//				fd.setFdofficialpic(rs.getString("fdofficialpic"));
//				fd.setFdview(rs.getString("fdview"));
//				fd.setFdusername(rs.getString("fdusername"));
//				fd.setFdusertaste(rs.getFloat("fdusertaste"));
//				fd.setFduserenvir(rs.getFloat("fduserenvir"));
//				fd.setFduserservice(rs.getFloat("fduserservice"));
//				fd.setFduserreview(rs.getString("fduserreview"));
//				fd.setFduserlike(rs.getString("fduserlike"));
//				fd.setFduserpic(rs.getString("fduserpic"));
//				fd.setFdpic(rs.getString("fdpic"));
//				
////				st.setStuid(rs.getInt("stuid"));
////				st.setStuname(rs.getString("stuname"));
////				st.setStuage(rs.getInt("stuage"));
////				st.setStubirthday(rs.getDate("stubirthday"));
////				st.setStusex(rs.getInt("stusex"));
//				
//				fds.add(fd);
//			}
//			rs.close();
//		} catch (SQLException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//		return fds;
//	}
	//查询所有商户详情信息
	public List<FoodDetails> findAllFd(){
		String sql = "select * from fooddetails";
		return DataHandler.query(sql, null, FoodDetails.class);
	}
//	//页面显示用户自己的点评
//	public void saveFr(FoodReview fr) {
//		String sql = "insert into foodreview(frtaste, frenvironment, frservice, "
//						 + "frlike, frreview, frperpay, frfeatures) values(?,?,?,?,?,?,?)";
//		DataHandler.update(sql, new Object[]{fr.getFrtaste(), fr.getFrenvironment(), fr.getFrservice(), 
//													fr.getFrlike(), fr.getFrreview(), fr.getFrperpay(),
//													fr.getFrfeatures()});
//	}
	//查询所有商户详情信息
			public List<UserReview> findAllUr(){
				String sql = "select * from userreview";
				return DataHandler.query(sql, null, UserReview.class);
			}
	
		
		//根据ID 显示商户详情信息
	public List<FoodDetails> findByIdFd(int fdid){
		String sql = "select * from fooddetails where fdid="+fdid;
//		DataHandler.update(sql, new Object[]{fd});
	    return DataHandler.query(sql, null, FoodDetails.class);
	}
	//保存商户详情信息
	public void saveFd(FoodDetails fd){
		String sql = "insert into fooddetails(fdname,fdcomment,fdperpay,fdtaste,fdenvironment,"
						+ "fdservice,fdaddress,fddetaddress,fdtel,fdbushours,fdprice,fdpricepic,"
							+ "fdpricename,fdrecdis,fdrecdispic,fdenvironmentpic,fdpricelistpic,fdofficialpic,"
								+ "fdview,fdusername,fdusertaste,fduserenvir,fduserservice,fduserreview,fduserlike,"
									+ "fduserpic,fdpic) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
	DataHandler.update(sql, new Object[]{fd.getFdname(),fd.getFdcomment(),fd.getFdperpay(),fd.getFdtaste(),fd.getFdenvironment(),
											fd.getFdservice(),fd.getFdaddress(),fd.getFddetaddress(),fd.getFdtel(),fd.getFdbushours(),fd.getFdprice(),fd.getFdpricepic(),
											fd.getFdpricename(),fd.getFdrecdis(),fd.getFdrecdispic(),fd.getFdenvironmentpic(),fd.getFdpricelistpic(),fd.getFdofficialpic(),
											fd.getFdview()});
	}
	//删除商户详细信息
	public void deleteFd(int fdid){
		String sql = "delete from fooddetails where fdid=?";
		DataHandler.update(sql, new Object[]{fdid});
	}
	//修改商户详细信息
	public void updateFd(FoodDetails fd){
		String sql = "update fooddetails set fdname=?,fdcomment=?,fdperpay=?,fdtaste=?,,fdenvironment=?,"
						+ "fdservice=?,fdaddress=?,fddetaddress=?,fdtel=?,fdbushours=?,fdprice=?,fdpricepic=?,"
							+ "fdpricename=?,fdrecdis=?,fdrecdispic=?,fdenvironmentpic=?,fdpricelistpic=?,fdofficialpic=?,"
								+ "fdview=?,fdusername=?,fdusertaste=?,fduserenvir=?,fduserservice=?,fduserreview=?,fduserlike=?,"
									+ "fduserpic=?,fdpic=? where fdid=?";
	DataHandler.update(sql, new Object[]{fd.getFdname(),fd.getFdcomment(),fd.getFdperpay(),fd.getFdtaste(),fd.getFdenvironment(),
											fd.getFdservice(),fd.getFdaddress(),fd.getFddetaddress(),fd.getFdtel(),fd.getFdbushours(),fd.getFdprice(),fd.getFdpricepic(),
												fd.getFdpricename(),fd.getFdrecdis(),fd.getFdrecdispic(),fd.getFdenvironmentpic(),fd.getFdpricelistpic(),fd.getFdofficialpic(),
													fd.getFdview(),fd.getFdid()});
	}
	//分页及模糊查询
	public <E> List<E> findCurrentPageData(PageHandler handler) {
		String sql = "select * from userreview limit ?,?";
//		if (handler.getCond() != null && handler.getCond().length() != 0) {
//			sql += " where " + handler.getConditonSQL();
//		}
		return DataHandler.query(sql, new Object[]{(handler.getCurrentPage()-1)*handler.getPageSize(),handler.getPageSize()},UserReview.class);
	}
	public <E> List<E> findCurrentPageDatadesc(PageHandler handler) {
		

		return  null;
		}
	public int findCountPage(PageHandler handler) {
		String sql = "select ceil(count(*)/?) from userreview";
//		if (handler.getCond() != null && handler.getCond().length() != 0) {
//			sql += " where " + handler.getConditonSQL();
//		}
		return Integer.parseInt(DataHandler.uniqueQuery(sql, new Object[]{handler.getPageSize()}).toString());
	}
	public <E>List<E> findUr(sqlHandler handler) {
		String sql = "select * from userreview";
		if (handler.getCond() != null && handler.getCond().length() != 0) {
			sql += " where " + handler.getConditionSQL();
		}
		return DataHandler.query(sql, null, UserReview.class);
	}
	public <E> List<E> foods(String a, PageHandler handler) {
		// TODO Auto-generated method stub
		return null;
	}
	

}
